<template>
  <div class="box6">
    <div class="title">
      <p>热门景区排行</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <div class="echarts" ref="charts"></div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'
let charts = ref()
onMounted(() => {
  let mycharts = echarts.init(charts.value)
  mycharts.setOption({
    //存放echarts的元素节点需要设置宽高才能正常显示
    title: {
      text: '景区排行',
      link: 'http://www.baidu.com',
      left: '40%',
      textStyle: {
        color: 'yellowgreen',
        fontSize: 20,
      },
      subtext: '各大景区排行', //子标题
      subtextStyle: {
        color: 'yellowgreen',
        fontSize: 16,
      },
    },
    xAxis: {
      type: 'category', //让图形在x轴上均匀分布
    },
    yAxis: {},
    grid: {
      top: 60,
      bottom: 20,
      left: 20,
    },
    series: [
      {
        type: 'bar',
        data: [10, 20, 30, 40, 50, 60, 70],
        //图形的文字
        label: {
          show: true,
          position: 'insideTop',
          color: 'yellowgreen',
        },
        //是否显示背景颜色
        showBackground: true,
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: '#8882A1', // 0% 处的颜色
            },
            {
              offset: 1,
              color: '#F6F6F6', // 100% 处的颜色
            },
          ],
        },
        //柱条的样式
        itemStyle: {
          borderRadius: [5, 5, 0, 0], //圆角效果
          color: function (data: any) {
            //给每个柱条设置不同的颜色
            let arr = ['red', 'green', 'blue', 'yellow', '#876', '#438', '#8f6']
            return arr[data.dataIndex]
          },
        },
      },
      //在一个容器内展示多个图形图表
      {
        type: 'line',
        data: [10, 20, 30, 40, 50, 60, 70],
      },
    ],
  })
})
</script>

<style scoped lang="scss">
.box6 {
  width: 100%;
  height: 100%;
  margin: 20px 0;
  background: url('../../images/dataScreen-main-cb.png') no-repeat;
  background-size: 100% 100%;
  .title {
    margin-left: 2px;
    p {
      color: white;
      font-size: 20px;
    }
  }
  .echarts {
    height: 80%;
    width: 100%;
  }
}
</style>
